prepare("SELECT * FROM students WHERE id = ?");
$stmt->execute([$student_id]);
$student = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$student) {
die("Student not found!");
}
// Get student's exam results with detailed information
$stmt = $pdo->prepare("
SELECT
r.*,
es.exam_id,
es.start_time,
es.end_time,
e.name as exam_name,
e.year as exam_year,
e.duration as exam_duration,
sub.name as subject_name,
sub.code as subject_code,
TIMESTAMPDIFF(MINUTE, es.start_time, es.end_time) as time_taken_minutes
FROM results r
JOIN exam_sessions es ON r.session_id = es.id
JOIN exams e ON es.exam_id = e.id
LEFT JOIN subjects sub ON e.subject_id = sub.id
WHERE es.student_id = ?
ORDER BY r.submitted_at DESC
");
$stmt->execute([$student_id]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Calculate student statistics
$total_exams = count($results);
$total_questions_attempted = array_sum(array_column($results, 'questions_attempted'));
$total_correct_answers = array_sum(array_column($results, 'correct_answers'));
$total_questions = array_sum(array_column($results, 'total_questions'));
$average_score = $total_exams > 0 ? array_sum(array_column($results, 'percentage')) / $total_exams : 0;
$highest_score = $total_exams > 0 ? max(array_column($results, 'percentage')) : 0;
$lowest_score = $total_exams > 0 ? min(array_column($results, 'percentage')) : 0;
// Calculate performance by subject
$subject_performance = [];
foreach ($results as $result) {
$subject = $result['subject_name'] ?: 'Unknown Subject';
if (!isset($subject_performance[$subject])) {
$subject_performance[$subject] = [
'exams_taken' => 0,
'total_score' => 0,
'highest_score' => 0,
'lowest_score' => 100
];
}
$subject_performance[$subject]['exams_taken']++;
$subject_performance[$subject]['total_score'] += $result['percentage'];
$subject_performance[$subject]['highest_score'] = max($subject_performance[$subject]['highest_score'], $result['percentage']);
$subject_performance[$subject]['lowest_score'] = min($subject_performance[$subject]['lowest_score'], $result['percentage']);
}
// Calculate averages for each subject
foreach ($subject_performance as $subject => &$performance) {
$performance['average_score'] = $performance['total_score'] / $performance['exams_taken'];
}
// Get recent activity (last 5 exams)
$recent_exams = array_slice($results, 0, 5);
// Calculate improvement trend
$improvement_trend = [];
if (count($results) >= 2) {
$first_half = array_slice($results, 0, ceil(count($results) / 2));
$second_half = array_slice($results, ceil(count($results) / 2));
$first_avg = array_sum(array_column($first_half, 'percentage')) / count($first_half);
$second_avg = array_sum(array_column($second_half, 'percentage')) / count($second_half);
$improvement_trend['trend'] = $second_avg - $first_avg;
$improvement_trend['percentage'] = $first_avg > 0 ? (($second_avg - $first_avg) / $first_avg) * 100 : 0;
}
?>
Student Results -
← Back to Students
Registration Number:
📧
📞
📅
Joined:
📊
Exams Taken:
%
Average Score
Across all exams
Exams Taken
Total attempts
%
Highest Score
Best performance
%
Lowest Score
Worst performance
0): ?>
Score Progress
Performance Distribution
0): ?>
Exam Results History
| Exam |
Subject |
Score |
Percentage |
Performance |
Time Taken |
Submitted |
Actions |
= 80) {
$score_class = 'score-excellent';
$performance_badge = 'badge-excellent';
$performance_text = 'Excellent';
} elseif ($result['percentage'] >= 60) {
$score_class = 'score-good';
$performance_badge = 'badge-good';
$performance_text = 'Good';
} elseif ($result['percentage'] >= 40) {
$score_class = 'score-average';
$performance_badge = 'badge-average';
$performance_text = 'Average';
} else {
$score_class = 'score-poor';
$performance_badge = 'badge-poor';
$performance_text = 'Poor';
}
$time_taken = $result['time_taken_minutes'];
$completion_percentage = min(100, ($time_taken / $result['exam_duration']) * 100);
?>
|
|
|
/
attempted
|
%
|
|
= 60) {
$hours = floor($time_taken / 60);
$minutes = $time_taken % 60;
echo sprintf('%dh %dm', $hours, $minutes);
} else {
echo sprintf('%dm', $time_taken);
}
?>
(% of allocated time)
|
|
|
📊
No Exam Results Yet
hasn't taken any exams yet.
Results will appear here once the student completes an exam.